package com.jsp.dao.impl;

import com.jsp.dao.EmployeeDao;
import com.jsp.entity.Employee;

import java.util.List;

/**
 * @author wzm
 * @create 2023-03-10 10:20
 */
public class EmployeeDaoImpl extends BaseDao implements EmployeeDao {
    @Override
    public int insertEmp(Employee employee) {
        String sql = "insert into employee values(?,?,?,?,?,?)";
        return update(sql,0,employee.getUsername(), employee.getPassword(),employee.getAge(),employee.getPhone(),employee.getStatus());
    }

    @Override
    public int deleteEmp(Employee employee) {
        String sql = "delete from employee where id = ?";
        return update(sql,employee.getId());
    }

    @Override
    public int updateEmp(Employee employee) {
        String sql = "update employee set username = ?,password = ?,age = ?,phone = ?,status = ? where id = ?";
        return update(sql,employee.getUsername(), employee.getPassword(),employee.getAge(),employee.getPhone(),employee.getStatus(),employee.getId());
    }

    @Override
    public Employee selectById(Employee employee) {
        String sql = "select * from employee where id  = ?";
        return selectForOne(Employee.class,sql,employee.getId());
    }

    @Override
    public List<Employee> selectByList() {
        String sql = "select * from employee";
        return selectForList(Employee.class,sql);
    }
}
